package com.tianyadu.security.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @FileName: TimeAspect
 * @Description:
 * @author: xueyj
 * @create: 2018-12-05 07:36
 */
@Aspect
@Component
@Slf4j
public class TimeAspect {

    /**
      * @Description: Around环绕通知
      * @param:
      * @return:
      * @author:
      * @date:   2018/12/5 7:47
      */
    @Around("execution(* com.tianyadu.security.controller.UserController.*(..))")
    public Object handleControllerMethod(ProceedingJoinPoint pjp) throws Throwable {
        log.info("time aspect 被调用");
        Object[] args = pjp.getArgs();
        for (Object arg : args) {
            log.info("arg is 【{}】", arg);
        }
        long start = System.currentTimeMillis();
        Object object = pjp.proceed();
        log.info("time aspect 耗时:【{}】", (System.currentTimeMillis() - start));
        log.info("time aspect 调用结束");
        return object;
    }
}
